//===------------ ReactorInstrinsics.cpp
//
//             This file is part of the reactor project
//                Author: R-Core Team
//
//===---------------------------------------------------------------------===//

#include "ReactorIntrinsics.h"

using namespace R;

void ReactorIntrinsics::init(llvm::Module* M) {
	BaseIntrinsics::init(M);
	loadCommonTypes(M);
}

void ReactorIntrinsics::loadCommonTypes(llvm::Module* selfModule) {
	typeInt64  = llvm::Type::getInt64Ty(selfModule->getContext());

#define z_getType(name) ({																			\
		llvm::Type* t = selfModule->getTypeByName("class."name);	\
		rerror_on(!t, "unable to find type: class."name);					\
		llvm::PointerType::get(t, 0);															\
})

	typeRModule  = z_getType("R::RModule");
	typeEnv      = z_getType("R::Environment");
	typeAny      = z_getType("R::Any");
	typeFunInfo  = z_getType("R::FunInfo");

	typepAny     = llvm::PointerType::get(typeAny, 0);

#undef z_getType

	rfunctionType = llvm::FunctionType::get(typeAny, false);
}
